package com.yueyang.sojourn.server.model.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 支付相关枚举
 * @author Andy.yang
 * @version v1
 * @summary
 * @Copyright (c) 2019, YueYang Group All Rights Reserved.
 * @since 2020/4/1
 */
public interface PayConstants {
    /**
     * @author andy.yang
     * @summary 第三方支付系统中账户类型 枚举
     * @Copyright (c) 2020, Yueyang Group All Rights Reserved.
     * @since 2020-03-26
     */
    @AllArgsConstructor
    enum ThirdPayAccountTypeEnum{
        /**
         * 交易付款方/收款方类型类型 枚举
         */
        WX_PERSON_WECHATID("PERSONAL_WECHATID", "个人微信号"),
        WX_PERSONAL_OPENID("PERSONAL_OPENID","个人openid（由父商户APPID转换得到）"),
        WX_PERSONAL_SUB_OPENID("PERSONAL_SUB_OPENID","个人sub_openid（由子商户APPID转换得到）"),
        WX_MERCHANT("MERCHANT_ID", "商户"),
    //    ZFB_PERSON("xxx", "支付宝个人")
        ;

        @Getter
        private String code;

        @Getter
        private String desc;

        public static ThirdPayAccountTypeEnum ofCode(String code) {
            return Arrays.stream(ThirdPayAccountTypeEnum.values()).filter(operStatusEnum -> operStatusEnum.code == code).findFirst().orElse(null);
        }
    }

    /**
     * @author andy.yang
     * @summary 第三方支付系统中账户 与 主商户之间的关系 枚举
     * @Copyright (c) 2020, Yueyang Group All Rights Reserved.
     * @since 2020-03-26
     */
    @AllArgsConstructor
    enum ThirdPayAccountRelationTypeEnum{

        /**
         * 交易付款方/收款方类型类型 枚举
         */
        WX_SERVICE_PROVIDER("SERVICE_PROVIDER", "服务商"),
        WX_STORE("STORE","门店"),
        WX_STAFF("STAFF","员工"),
        WX_STORE_OWNER("STORE_OWNER", "店主"),
        WX_PARTNER("PARTNER", "合作伙伴"),
        WX_HEADQUARTER("HEADQUARTER", "总部"),
        WX_BRAND("BRAND", "品牌方"),
        WX_DISTRIBUTOR("DISTRIBUTOR", "分销商"),
        WX_USER("USER", "用户"),
        WX_SUPPLIER("SUPPLIER", "供应商"),
        WX_CUSTOM("CUSTOM", "自定义")
        //    ZFB_PERSON("xxx", "支付宝个人")
        ;

        @Getter
        private String code;

        @Getter
        private String desc;

        public static ThirdPayAccountTypeEnum ofCode(String code) {
            return Arrays.stream(ThirdPayAccountTypeEnum.values()).filter(operStatusEnum -> operStatusEnum.code == code).findFirst().orElse(null);
        }
    }


    /**
     * @author andy.yang
     * @summary 交易状态 枚举
     * @Copyright (c) 2020, Yueyang Group All Rights Reserved.
     * @since 2020-02-13
     */
    @AllArgsConstructor
    enum TransactionStatusEnum implements IEnum {
    //    SUCCESS—支付成功
    //
    //    REFUND—转入退款
    //
    //    CLOSED—已关闭
    //
    //    REVOKED—已撤销(刷卡支付)
    //
    //    USERPAYING--用户支付中
    //
    //    PAYERROR--支付失败(其他原因，如银行返回失败)

        /**
         * 交易状态 枚举
         */
        PAYING(10, "预支付"),
        PAID(20, "已支付"),
        DEALED(30, "已成交"),
        CANCEL(40, "已取消"),
        REFUNDING(49, "预退款"),
        REFUNDED(50, "已退款"),
        CLOSED_EXPIRE(70, "过预支付期-已关闭"),
        CLOSED_REFUND_NOT_EXISTS(71, "退款交易单不存在-已关闭");

        @Getter
        private int code;

        @Getter
        private String desc;

        public static TransactionStatusEnum ofCode(Integer code) {
            return Arrays.stream(TransactionStatusEnum.values()).filter(operStatusEnum -> operStatusEnum.code == code).findFirst().orElse(null);
        }
    }

    /**
     * @author andy.yang
     * @summary 交易类型 枚举
     * @Copyright (c) 2020, Yueyang Group All Rights Reserved.
     * @since 2020-03-28
     */
    @AllArgsConstructor
    enum TransactionTypeEnum implements IEnum {

        /**
         * 交易类型 枚举
         */
        PAY(1, "付款"),
        REFUND(2, "退款");

        @Getter
        private int code;

        @Getter
        private String desc;

        public static TransactionTypeEnum ofCode(Integer code) {
            return Arrays.stream(TransactionTypeEnum.values()).filter(operStatusEnum -> operStatusEnum.code == code).findFirst().orElse(null);
        }
    }


    @AllArgsConstructor
    enum TradeStateEnum{
        SUCCESS("SUCCESS","支付成功"),
        REFUND("REFUND","转入退款"),
        NOTPAY("NOTPAY","未支付"),
        CLOSED("CLOSED","已关闭"),
        REVOKED("REVOKED","已撤销（刷卡支付"),
        USERPAYING("USERPAYING","用户支付中"),
        PAYERROR("PAYERROR","其他原因，如银行返回失败");

        @Getter
        private String code;
        @Getter
        private String desc;

        public static TradeStateEnum ofCode(String code) {
            return Arrays.stream(TradeStateEnum.values()).filter(operStatusEnum -> operStatusEnum.code == code).findFirst().orElse(null);
        }
    }
}
